import axios from "@/util/http";

export default {
  state: {
    order_item_list: [],
    unfinished_order_item_list: [],
    finished_order_item_list: [],
  },
  getters: {},
  mutations: {},
  actions: {
    get_order_item_by_order_id(context, data) {
      const url = "/order/item/get/order/item/by/order/id/";
      const config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      data.token = null;
      axios
        .post(url, data, config)
        .then((resp) => {
          context.state.order_item_list = resp.data.data;
        })
        .catch((resp) => {
          console.log(resp);
        });
    },
    get_all_unfinished_order_item(context, data) {
      const url = "/order/item/get/all/unfinished/";
      const config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      data.token = null;
      axios
        .post(url, data, config)
        .then((resp) => {
          context.state.unfinished_order_item_list = resp.data.data;
        })
        .catch((resp) => {
          console.log(resp);
        });
    },
    get_all_finished_order_item_by_chef_id(context, data) {
      const url = "/order/item/get/all/finished/by/chef/id/";
      const config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      data.token = null;
      axios
        .post(url, data, config)
        .then((resp) => {
          context.state.finished_order_item_list = resp.data.data;
        })
        .catch((resp) => {
          console.log(resp);
        });
    },
    finish_order_item(context, data) {
      const url = "/order/item/done/";
      const config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      data.token = null;
      // console.log(data);
      axios
        .post(url, data, config)
        .then((resp) => {
          data.success(resp.data);
        })
        .catch((resp) => {
          console.log(resp);
        });
    },
  },
  modules: {},
};
